/*
 *  ckr_spec_greater_than_or_equal_comparison.cpp
 *  ckrSpec
 *
 *  Created by C. Keith Ray on 2006.11.05.
 *  Copyright 2006 __MyCompanyName__. All rights reserved.
 *
 */

#import "ckr_spec_cpp_specs.h"
#import "ckr_spec_cpp.h"

#include <iostream>
#include <sstream>
#include <vector>
#include <deque>

#include <assert.h>

using namespace std;
using namespace ckr;

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

static void int_values_greater_than_or_equal_in_should_be_greater_than_or_equal_reports_nothing();
static void int_values_not_greater_than_or_equal_in_should_be_greater_than_or_equal_report_failure();

static void cstrings_greater_than_or_equal_in_should_be_greater_than_or_equal_reports_nothing();
static void cstrings_not_greater_than_or_equal_in_should_be_greater_than_or_equal_report_failure();

static void cstrings_null_in_should_be_greater_than_or_equal_reports_failure();
static void	cstrings_both_null_in_should_be_greater_than_or_equal_reports_nothing();

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

void run_greater_than_or_equal_comparison_specs()
{
	int_values_greater_than_or_equal_in_should_be_greater_than_or_equal_reports_nothing();
	int_values_not_greater_than_or_equal_in_should_be_greater_than_or_equal_report_failure();

	cstrings_greater_than_or_equal_in_should_be_greater_than_or_equal_reports_nothing();
	cstrings_not_greater_than_or_equal_in_should_be_greater_than_or_equal_report_failure();

	cstrings_null_in_should_be_greater_than_or_equal_reports_failure();
	cstrings_both_null_in_should_be_greater_than_or_equal_reports_nothing();
}

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DECLARE_SPEC(Int_values_greater_than_or_equal_in_should_be_greater_than_or_equal);

void Int_values_greater_than_or_equal_in_should_be_greater_than_or_equal::spec()
{
	VALUE(1).SHOULD_BE_GREATER_THAN_OR_EQUAL_TO(1); // no output expected
	VALUE(3).SHOULD_BE_GREATER_THAN_OR_EQUAL_TO(2); // no output expected
}

static void int_values_greater_than_or_equal_in_should_be_greater_than_or_equal_reports_nothing()
{
	Int_values_greater_than_or_equal_in_should_be_greater_than_or_equal aContext;
	
	RecordingFailuresSpecListener listener;
	aContext.run_spec( & listener );
	std::string actual = listener.logStr();

	std::string expected;
	
	assert( expected == actual );
}

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DECLARE_SPEC(Int_values_not_greater_than_or_equal_in_should_be_greater_than_or_equal);

void Int_values_not_greater_than_or_equal_in_should_be_greater_than_or_equal::spec()
{
	VALUE(0).SHOULD_BE_GREATER_THAN_OR_EQUAL_TO(1); // failure msg expected
}

static void int_values_not_greater_than_or_equal_in_should_be_greater_than_or_equal_report_failure()
{
	Int_values_not_greater_than_or_equal_in_should_be_greater_than_or_equal aContext;
	
	RecordingFailuresSpecListener listener;
	aContext.run_spec( & listener );
	std::string actual = listener.logStr();

	std::string expected("0 (0) should be greater than or equal to 1 (1) FAILED in Int_values_not_greater_than_or_equal_in_should_be_greater_than_or_equal; line");

	std::string::size_type foundPos = actual.find( expected, 0 );
	assert( foundPos != std::string::npos );
}

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DECLARE_SPEC(CString_values_greater_than_or_equal_in_should_be_greater_than_or_equal);

void CString_values_greater_than_or_equal_in_should_be_greater_than_or_equal::spec()
{
	CSTRING_VALUE("2").SHOULD_BE_GREATER_THAN_OR_EQUAL_TO("2"); // no msg expected
	CSTRING_VALUE("3").SHOULD_BE_GREATER_THAN_OR_EQUAL_TO("1"); // no msg expected
}

static void cstrings_greater_than_or_equal_in_should_be_greater_than_or_equal_reports_nothing()
{
	CString_values_greater_than_or_equal_in_should_be_greater_than_or_equal aContext;

	RecordingFailuresSpecListener listener;
	aContext.run_spec( & listener );
	std::string actual = listener.logStr();

	const std::string expected;

	assert( expected == actual );
}

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DECLARE_SPEC(CString_values_not_greater_than_or_equal_in_should_be_greater_than_or_equal);

void CString_values_not_greater_than_or_equal_in_should_be_greater_than_or_equal::spec()
{
	CSTRING_VALUE("1").SHOULD_BE_GREATER_THAN_OR_EQUAL_TO("3"); // failure msg expected
}

static void cstrings_not_greater_than_or_equal_in_should_be_greater_than_or_equal_report_failure()
{
	CString_values_not_greater_than_or_equal_in_should_be_greater_than_or_equal aContext;

	RecordingFailuresSpecListener listener;
	aContext.run_spec( & listener );
	std::string actual = listener.logStr();

	const std::string expected("\"1\" (1) should be greater than or equal to \"3\" (3) FAILED in CString_values_not_greater_than_or_equal_in_should_be_greater_than_or_equal; line");

	std::string::size_type foundPos = actual.find( expected, 0 );
	assert( foundPos != std::string::npos );
}

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DECLARE_SPEC(CString_value_null_in_should_be_greater_than_or_equal);

void CString_value_null_in_should_be_greater_than_or_equal::spec()
{
	const char* nullString = NULL;

	CSTRING_VALUE(nullString).SHOULD_BE_GREATER_THAN_OR_EQUAL_TO("2"); // fail msg expected
	CSTRING_VALUE("3").SHOULD_BE_GREATER_THAN_OR_EQUAL_TO(nullString); // fail msg expected
}

static void cstrings_null_in_should_be_greater_than_or_equal_reports_failure()
{
	CString_value_null_in_should_be_greater_than_or_equal aContext;
	
	RecordingFailuresSpecListener listener;
	aContext.run_spec( & listener );
	std::string actual = listener.logStr();
	
	{
		const std::string expected1("nullString ((NULL POINTER)) should be greater than or equal to \"2\" (2) FAILED in CString_value_null_in_should_be_greater_than_or_equal; line");

		std::string::size_type foundPos1 = actual.find( expected1, 0 );
		assert( foundPos1 != std::string::npos );
	}
	{
		const std::string expected2("\"3\" (3) should be greater than or equal to nullString ((NULL POINTER)) FAILED in CString_value_null_in_should_be_greater_than_or_equal; line");

		std::string::size_type foundPos2 = actual.find( expected2, 0 );
		assert( foundPos2 != std::string::npos );
	}
}

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DECLARE_SPEC(CString_both_values_null_in_should_be_greater_than_or_equal);

void CString_both_values_null_in_should_be_greater_than_or_equal::spec()
{
	const char* nullString = NULL;
	const char* nullOtherString = NULL;

	CSTRING_VALUE(nullString).SHOULD_BE_GREATER_THAN_OR_EQUAL_TO(nullOtherString); // fail msg expected
}

static void cstrings_both_null_in_should_be_greater_than_or_equal_reports_nothing()
{
	CString_both_values_null_in_should_be_greater_than_or_equal aContext;

	RecordingFailuresSpecListener listener;
	aContext.run_spec( & listener );
	std::string actual = listener.logStr();

	const std::string expected;

	assert( expected == actual );
}

//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
